package com.palominocia.nodocentral.clientedatosnodocentral;
import com.palominocia.capa_datos_nodo.servicios.NodoCentral;
import com.palominocia.capa_datos_nodo.servicios.NodoCentralImplService;
import com.palominocia.capa_datos_nodo.servicios.RespuestaArbol;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.xml.ws.BindingProvider;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.ws.security.WSPasswordCallback;
/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        String username="jonathan1";
        final String password="123456";
        NodoCentralImplService serv = new NodoCentralImplService();
        NodoCentral port = serv.getNodoCentralImplPort();
        Client client = ClientProxy.getClient(port);
        Endpoint cxfEndpoint = client.getEndpoint();

        Map<String, Object> outProps = new HashMap<String, Object>();
        outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
        outProps.put(WSHandlerConstants.USER, username);
        outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
        //outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,ClientPasswordHandler.class.getName());
        
        outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {

            @Override
            public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
                pc.setPassword(password);
            }
        });

        WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
        cxfEndpoint.getOutInterceptors().add(wssOut);
        //System.out.println("sumando -->> "+port.ejecutaconsulta("ABC"));
        RespuestaArbol resp =port.generaArbol("2");
        List lista =resp.getQueryLista();
        System.out.println(""+lista.size());
    }
}
